package com.gome.ocean;

import java.lang.reflect.Field;
import java.nio.ByteBuffer;

public class Direct {

    public sun.misc.Unsafe getUnsafe() {
        Field f;
        try {
            f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
            f.setAccessible(true);
            return (sun.misc.Unsafe) f.get(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return null;
    }

    public static void main(String[] args) throws InterruptedException {

        System.out.println(System.getProperty("os.name"));
//        for (int i = 0; i < 1000; i++) {
//            ByteBuffer.allocateDirect(1024 * 1024 * 100);
//            //String aa[] = new String[i];
//        }

        // Direct direct = new Direct();
        // sun.misc.Unsafe unsafe = direct.getUnsafe();
        //
        // for (int i = 0; i < 100000; i++) {
        // long size = unsafe.allocateMemory(1024 * 1024 * 100);
        // unsafe.freeMemory(size);
        // }

    }
}
